#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <queue>
#include <vector>
#include <cstring>

using namespace std;
const int N = 810, INF = 0x3f3f3f3f;
typedef pair<int, int>PII;
int dist[N];
bool st[N];
vector<PII>edges[N];
int id[N];
int n, p, c;
int dijkstra(int s)
{
	memset(dist, 0x3f, sizeof dist);
	memset(st, 0, sizeof st);
	priority_queue<PII, vector<PII>, greater<PII>> heap;
	dist[s] = 0;
	heap.push({ 0,s });
	while (heap.size())
	{
		auto t = heap.top(); heap.pop();
		int u = t.second;
		if (st[u]) continue;
		st[u] = true;
		for (auto t : edges[u])
		{
			int v = t.first, w = t.second;
			if (dist[u] + w < dist[v])
			{
				dist[v] = dist[u] + w;
				heap.push({ dist[v],v });
			}
		}
	}
	int sum = 0;
	for (int i = 1; i <= n; i++)
	{
		if (dist[id[i]] == INF) return INF;
		sum += dist[id[i]];
	}
	return sum;
}
int main()
{
	cin >> n >> p >> c;
	for (int i = 1; i <= n; i++) cin >> id[i];
	for (int i = 1; i <= c; i++)
	{
		int u, v, w; cin >> u >> v >> w;
		edges[u].push_back({ v,w });
		edges[v].push_back({ u,w });
	}
	int ret = INF;
	for (int i = 1; i <= p; i++)
	{
		ret = min(ret, dijkstra(i));
	}
	cout << ret << endl;
	return 0;
}